﻿Ext.namespace('iOS.App.Photos');

Ext.define('PhotosList', {
	extend : 'BaseListView',

	statics : {
		BaseCls       : 'list-view',
        ListContainer : 'list-container',
        ListCls       : 'ios-photos-list',
        ListContent   : 'list-content',
        PhotosBooks   : 'photos-books',
        ToolBar       : 'photos-bar',
        AppCard       : 'photos-card',
        ListTarCard   : 'photos-books',
        Thumbnails    : 'list-thumbnails',
        ListTitle     : 'list-title',
        ListArrow     : 'list-arrow',
        PicsCount     : 'photos-pics-count'
    },

    /*
     * 图片存放的路径
     */
    _picsURL : 'resource/images/apps/photos/',

    _clickedColor: 'rgba(28, 82, 199, 1)',

    _clickedCls  : 'list-clicked',

    _initListHtml: function(){
        var sttc       = this.self,
            listHtml   = [];
    	listHtml = [
    		'<div class="' + sttc.ListContent + '">' +
                '<div class="' + sttc.Thumbnails + '"></div>' + 
                '<div class="' + sttc.ListTitle + '">相机胶卷 ' +
                    '<span class="' + sttc.PicsCount + '">(88)</span>' + 
                '</div>' +
                '<div class="' + sttc.ListArrow + '"></div>' +
            '</div>',
    		'<div class="' + sttc.ListContent + '">' +
                '<div class="' + sttc.Thumbnails + '"></div>' + 
                '<div class="' + sttc.ListTitle + '">照片图库 ' +
                    '<span class="' + sttc.PicsCount + '">(68)</span>' +
                '</div>' +
                '<div class="' + sttc.ListArrow + '"></div>' +
            '</div>',
    	];
        this._listHtml = listHtml;
    },

    clickHandler: function(e){
        var that  = e.data.scope || this,
            sttc  = that.self,
            $this = $(this),
            title = $this.find('.' + sttc.ListTitle),
            count = $this.find('.' + sttc.PicsCount);
        count.addClass(that._clickedCls);
        title.addClass(that._clickedCls);
        setTimeout(function(){
            title.removeClass(that._clickedCls);
            count.removeClass(that._clickedCls);
        }, 550); 
        that.callParent([e, this]);
    },

    _afterRender: function(){
        this.callParent();
        this._setListThumbnails();
    },

    _setListThumbnails: function(){
        function getURL(i){
            return  'url(' + baseURL + 'ios-photos-list' + i + '.png)';
        }
        var sttc    = this.self,
            lists   = this.getElCacheByCls(sttc.Thumbnails),
            baseURL = this._picsURL;
        for(var i   = 0; i < lists.length; i++){
            lists.eq(i).css('backgroundImage', getURL(i));
        }
    }
});

iOS.App.Photos.PhotosList = PhotosList;